In a typical high level programming language, for example one falling under the Microsoft .NET software development platform, the data type of a programming element refers to what kind of data it can hold and how it stores that data. Data types apply to all values that can be stored in computer memory or participate in the evaluation of an expression. Thus, every variable, literal, constant, enumeration, property, procedure parameter, procedure argument, and procedure return value will typically have a data type. A data type is a value type if it holds the data within its own memory allocation. By comparison, a reference type contains a pointer to another memory location that holds the data.
In .NET, reference types are allocated on the program heap—that section of memory that may persist past the current function or thread. A caller for the creation of a reference type will get back the pointer to the object or the address of the object's memory in the heap. The pointer uses a small amount of memory, for example four bytes, on the program stack which is a memory section that exists for the currently executing part of the program, and which typically holds reserved space for local variables and arguments during procedure calls.
Value types may typically be allocated on the program stack. When a function executes, all of the value types it uses are known before hand, and are laid out before execution begins in the function. In addition, the memory allocated to value types is released when the function finishes (i.e., returns). Accordingly, a copy of the memory is returned to the caller and the value types passed to a function are copied.
Boxing and unboxing may be viewed as a special form of copying for value types in .NET. Boxing takes a value type inside a wrapper (i.e., a “box”) where it can then behave like a heap object. Thus by wrapping value types as heap objects, a value type can be used as if it were a reference type. A boxed value type instance can also be converted back to its original form (i.e., unboxing).
By comparison to .NET, other execution environments (such those using JavaScript) only give programmers access to reference types, but not their underlying pointer representations. Such restrictions may be justified to safeguard against security breaches that could occur through misuse of pointers to gain improper access to memory addresses. Nor do these execution environments support value type boxing. However, for .NET code to be executed in such alternative environments, support for the constructs of pointers and boxing needs to be provided.
This Background is provided to introduce a brief context for the Summary and Detailed Description that follow. This Background is not intended to be an aid in determining the scope of the claimed subject matter nor be viewed as limiting the claimed subject matter to implementations that solve any or all of the disadvantages or problems presented above.